<?php
/*
Template Name: Portfolio  - 4 Circles
*/
get_header(); ?>


<?php if ( have_posts() ) while ( have_posts() ) : the_post(); 

    $content = get_the_content();
	$title = get_the_title();

	// Posts per page
	$posts_per_page = get_post_meta($post->ID, 'posts_per_page', true);
	if ( $posts_per_page == '' ) $posts_per_page = '-1';

endwhile; ?>

<?php $portfolios = get_portfolios(); 

foreach ($portfolios as $portfolio):
	if (is_page($portfolio->page)): ?>
	
    	<section id="content_wrapper">
			
            <h1 class="page_title">
                <?php echo $title; ?>
            </h1>
            <div class="page_content">
                <?php the_content(); ?>
            </div><!-- .page_content -->
                            
            <?php
            
            $portfolio_ids = explode(',', $portfolio->category);
    
            $args = array(
                'post_type' => 'portfolios',
				'posts_per_page' => $posts_per_page,
                'tax_query' => array(
                    array(
                        'taxonomy' => 'portfolio_category',
                        'field' => 'id',
                        'terms' => $portfolio_ids
                    )
                ),
				'paged' => $paged
            );
            
            $wp_query = new WP_Query( $args );
    
            global $more;
            $more = 0;
            $post_count = 0;
            

            echo '<div id="portfolio_4_circles" class="clearfix">';

            if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
                
                if ( has_post_thumbnail() ) $thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
                
                $article_margin = '';
                if ( $post_count % 4 == 3 )
                    $article_margin = 'style="margin-right: 0px;"';
                
                $thumbnail_size = 'w=210&amp;h=210';
				$image_source = get_template_directory_uri().'/includes/timthumb.php?src='.$thumbnail_src.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100';
				$image_background_source = get_template_directory_uri().'/includes/timthumb.php?src='.$thumbnail_src.'&amp;'.$thumbnail_size.'&amp;zc=1&amp;q=100&amp;f=8|8|8|8|8|8|8';

				echo '<article class="item" '.$article_margin.'>';
					echo '<a class="portfolio_image" href="'; the_permalink(); echo '">';
						echo '<div class="zoom">';
							echo '<span></span>';
						echo '</div>';
						echo '<div class="on_top" style="background: url(\''; echo $image_source; echo '\');"></div>';
						echo '<div class="on_middle" style="background: url(\''; echo $image_background_source; echo '\');"></div>';
						echo '<div class="on_bottom"></div>';
					echo '</a>';
					echo '<div class="content">';
						the_title();
					echo '</div>';
					
				echo '</article>';
				
				if ( $post_count % 4 == 3 )
			       echo '<div class="content_horizontal_clear"></div>';
			   $post_count++;
            
            endwhile; endif;
            
			if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
			
            echo '</div>'; // END #portfolio_4_circles
            
            
            ?>
            
           
        </section> <!-- #content_wrapper -->
    
	<?php get_footer(); 

	return;
	endif;
endforeach;
?>
